Admin Console report to show table sizes; metrics for schema sizes#7170
Conversation
|
ERROR: A pull request from |
|
|
||
| setDescription("Shows info Postgres table sizes"); | ||
|
|
||
| addColumn(new ExprColumn(this, "table_schema", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".table_schema"), JdbcType.VARCHAR)); |
There was a problem hiding this comment.
I think this is the default behavior of BaseColumnInfo (no need for ExprColumn and SQLFragment). See BaseColumnInfo.getValueSql(String tableAliasName)
There was a problem hiding this comment.
You're right. Thanks. I updated all three special PG tables
| SELECT | ||
| table_schema, | ||
| table_name, | ||
| pg_table_size('"' || table_schema || '"."' || table_name || '"') AS table_size, |
There was a problem hiding this comment.
Ugh, this syntax is so weird. PG is very vague about how a VARCHAR gets converted to OID. This is also slightly weirder in that you're using the information_schema where OID doesn't exist.
Something like this against the native schema let's you get the OID directly.
SELECT pg_namespace.nspname as schema_name, pg_class.relname as table_name, pg_table_size(pg_class.oid)
FROM pg_class JOIN pg_namespace ON pg_class.relnamespace = pg_namespace.oid
WHERE pg_class.relkind = 'r' and nspname NOT IN ('pg_catalog', 'information_schema')
ORDER BY schema_name, table_name
There was a problem hiding this comment.
I don't see a SQL problem with the original. I just don't know what PG will do when converting the generated string to an OID when the table has double-quotes in the name.
There was a problem hiding this comment.
Arg. Stupid quotes.
I created a horrible schema and table name. I verified that quote_ident fixes the problem and resolves to regclass/OID correctly.
labkey-matthewb
left a comment
There was a problem hiding this comment.
Approved. Comments for you consideration.
|
@labkey-adam I added a filter to omit those PG internal schemas |
Rationale
If we know the sizes of tables we can make better choices about infrastructure and better estimate usage. Limited to Postgres.
Changes
modules.Core.databaseSchemaSizesmetric to roll up table sizes by schemaTasks 📍
SqlDialect.isSystemSchema().